<template>
  <div class="container">
    <!-- 登陆框布局 -->
    <div class="form">
      <div class="box-img">
        <img
          src="https://www.escook.cn/vue-shop/img/logo.82b9c7a5.png"
          alt=""
        />
      </div>
      <el-form :model="user" :rules="rules" ref="user">
        <el-form-item prop="username">
          <el-input
            prefix-icon="el-icon-user-solid"
            v-model="user.username"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            prefix-icon="el-icon-s-goods"
            v-model="user.password"
          ></el-input>
        </el-form-item>
        <div class="float">
          <el-button type="primary" @click="login('user')">登陆</el-button>
          <el-button>重置</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import { login } from "@/http/http.js";
export default {
  name: "",
  components: {},
  props: [],
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入账号", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 17,
            message: "长度在 3 到 17 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 登录
    async login() {
      const { data: res } = await login(this.user);
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg);
      }
      this.$message.success(res.meta.msg);
      window.sessionStorage.setItem("token", res.data.token);
      // 跳转到后台主页，
      this.$router.push("/admin/index");
    },
  },
};
</script>

<style lang='scss' scoped>
.container {
  background-color: #2b4b6b;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  .form {
    border-radius: 3px;
    box-shadow: 0 0 10px #ddd;
    position: relative;
    width: 26%;
    height: 130px;
    padding: 100px 20px;
    background: white;
    .box-img {
      position: absolute;
      top: -60px;
      left: 33%;
      width: 130px;
      height: 130px;
      padding: 10px;
      border: 1px solid #efefef;
      border-radius: 50%;
      background: white;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #efefef;
      }
    }
    .el-form {
      margin-top: 30px;
    }
    .float {
      float: right;
    }
  }
}
</style>
